package com.example.mailsender.controller;

import com.example.mailsender.Service.MailService;
import com.example.mailsender.dao.MailDao;
import com.example.mailsender.dao.MessageDao;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.InputStreamSource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.mail.MessagingException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

@RestController
@Api("邮件服务")
public class MailController {
    @Autowired
    MailService mailService;

    @ApiOperation("发送不带附件的文件")
    @PostMapping("/send")
    @CrossOrigin
    public String sendMail(@RequestBody MailDao mailDao) throws MessagingException {
        String res = mailService.sendMailHtml(mailDao);
        return res.equals("ok")?"邮件发送成功":"邮件发送失败";
    }
    @ApiOperation("发送不带附件的文件")
    @PostMapping("/mssend")
    @CrossOrigin
    public String sendMail(@RequestBody MessageDao messageDao) throws MessagingException {
        String res = mailService.sendMailHtml(messageDao);
        return res.equals("ok")?"邮件发送成功":"邮件发送失败";
    }
}
